package com.tnovoselec.android.mojevijesti.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tnovoselec.android.mojevijesti.R;
import com.tnovoselec.android.mojevijesti.dto.NewsItemDto;

public class NewsDetailsAdapter extends PagerAdapter {

	private List<NewsItemDto> data;
	private Context context;
	
	public NewsDetailsAdapter(List<NewsItemDto> data,Context context){
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public void startUpdate(View container) {
		// TODO Auto-generated method stub

	}

	@Override
	public Object instantiateItem(View container, int position) {
		View root = LayoutInflater.from(context).inflate(R.layout.news_details_item, (ViewGroup) container, false);
		WebView webview = (WebView) root.findViewById(R.id.news_details_item_webview);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.setWebViewClient(new WebViewClient());
		
		webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
		Log.i("url", "loading url" + data.get(position).getLink());
		webview.loadUrl(data.get(position).getLink());

		((ViewPager) container).addView(root, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

		return root;
	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView((View) object);

	}

	@Override
	public void finishUpdate(View container) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return object == view;
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void restoreState(Parcelable state, ClassLoader loader) {
		// TODO Auto-generated method stub

	}
	


}
